#include <cassert>
#include <cstring>
#include <iostream>
#include <cstdlib>   
#include <sys/types.h>
#include <stdio.h>
#include <sys/socket.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/wait.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <string.h>
#include <pthread.h>
#include <signal.h>
#include <stdbool.h>
#include <termio.h>
#include <fcntl.h>
#include <getopt.h>
#include <unistd.h>
#define MAX_LEN 200



void readuci(char cmd[], char para[]) //从uci命令中获取参数
{
	FILE *fp;
	int i = 0;
	if((fp = popen(cmd,"r")) == NULL)
	{
		printf("Get serviceid false!,cmd=%s,para=%s\n",cmd,para);
		sprintf(para,"%s","00000000");
		return;
	}
	memset(para,0,sizeof(para));
	if(fgets(para,MAX_LEN, fp)!=NULL)
	{
		while(para[i] != '\n')
		{
			i++;
		}
		para[i] = '\0';
	}
	pclose(fp);
}

int main()
{

	char proto[20];

   system("killall openvpn");
   system("killall relayvpn");
   system("killall edge");
   system("killall client");
   system("killall directconnect");
   
sleep(2);
	readuci("uci get routedif.@routedif[0].vpnproto",proto);
	if(strcmp(proto,"none")==0)
	{
			system("/jffs/sbin/client &");
	}
	if(strcmp(proto,"t2uvpn")==0)
	{
			system("/jffs/sbin/t2uvpn &");
	}
	else
	{
		system("/jffs/sbin/directconnect &");
	}

}

